/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fyx.secure.controll;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.fyx.secure.entity.SecureUser;

/**
 *
 * @author xljan
 */
@Stateless
public class SecureUserFacade extends AbstractFacade<SecureUser> implements SecureUserFacadeLocal {

    @PersistenceContext(unitName = "FyxCorePU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public SecureUserFacade() {
        super(SecureUser.class);
    }

    @Override
    public SecureUser findByUsername(String username) {
        try {
            SecureUser user = em.createNamedQuery("SecureUser.findByUsername",
                    SecureUser.class).setParameter("username", username).
                    getSingleResult();
            return user;
        } catch (NoResultException ex) {
            return null;
        }
    }
}
